const mongoose = require('mongoose');
const config = require('../config')
mongoose.connect('mongodb://localhost/' + config.dbBase).then(
    () => {
        console.log('---> 数据库连接成功')
        write()
    },
    err => { console.log('---> 数据库连接失败\n' + err) }
)

const data = [
    {
        "name": "systemSettings",
        "parentId": 0,
        "id": 10035,
        "meta": {
            "title": "系统设置",
            "icon": "setting",
            "show": true
        },
    },
    {
        "name": "basicInformation",
        "parentId": 10035,
        "id": 10036,
        "meta": {
            "title": "基本资料",
            "show": true
        },
    },
    {
        "name": "auxiliaryData",
        "parentId": 10035,
        "id": 10037,
        "meta": {
            "title": "辅助资料",
            "show": true
        }
    },

    {
        "name": "customer",
        "parentId": 0,
        "id": 10039,
        "meta": {
            "title": "客户",
            "show": false
        }
    },
    {
        "name": "supplier",
        "parentId": 0,
        "id": 10040,
        "meta": {
            "title": "供应商",
            "show": false
        }
    },
    {
        "name": "goods",
        "parentId": 0,
        "id": 10041,
        "meta": {
            "title": "商品管理",
            "show": false
        }
    },
    {
        "name": "warehouse",
        "parentId": 0,
        "id": 10042,
        "meta": {
            "title": "仓库管理",
            "show": false
        }
    },
    {
        "name": "staff",
        "parentId": 0,
        "id": 10043,
        "meta": {
            "title": "职员管理",
            "show": false
        }
    },
    {
        "name": "accounts",
        "parentId": 0,
        "id": 10044,
        "meta": {
            "title": "账户",
            "show": false
        }
    }
]


write = () => {
    const menuSchema = new mongoose.Schema({
        name: String,
        parentId: Number,
        id: Number,
        meta: {
            title: String,
            icon: String,
            show: Boolean
        },
    })
    Menu = mongoose.model('user', menuSchema);
    const lenth = data.length
    console.log(lenth);
    for (let i = 0; i < lenth; i++) {
        console.log(i);
        let menu = {} 
        menu = new Menu(data[i])
        menu.save()
        console.log('..............');
    }

}

